package zyu.qwq.qwq_bungee_plugin;

import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.Connection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ChatEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;


public class PlayerChatEvent implements Listener {
    @EventHandler
    public void onChat(ChatEvent e){
        ProxiedPlayer sender = (ProxiedPlayer) e.getSender();
        String senderName = sender.toString();
        String msg = e.getMessage();
        String senderServerName = sender.getServer().getInfo().getName();

        if (msg.startsWith("/")){
            return;
        }


        TextComponent msg1 = new TextComponent("[" + senderName + "]: ");
        msg1.setBold(true);
        msg1.setColor(ChatColor.GRAY);

        TextComponent msg2 = new TextComponent(msg);
        msg2.setBold(false);
        msg2.setColor(ChatColor.DARK_GRAY);

        msg1.addExtra(msg2);


        for (ProxiedPlayer player: ProxyServer.getInstance().getPlayers()){
            if ( !player.getServer().getInfo().getName().equals(senderServerName) ){
                player.sendMessage(
                    msg1
                );
            }

        }

        ProxyServer.getInstance().getLogger().info(msg1.toPlainText());
    }
}
